<?php include("../includes/header-member.php") ?>
<title>LazySwim</title>
<link rel="stylesheet" href="store.css" type="text/css" />
</head>

<body>
<div id="page">
    <div id="page-top">
        <div id="page-bottom">
          <div id="header">
                <div id="header-info">
                    <h1>LAZYSWIM</h1>
                    <div class="description">Simplistic Swim System</div>
                </div>
				<!-- Header Goes Here -->
                <?php printHeader(); ?>
				<!-- Header Ends Here -->
                <div id="header-date">Today is <?php echo date('l, F jS, Y'); ?></div>
                <div id="header-cats">
				<!-- Welcome Message Starts Here -->
                    <ul>
					<?php include("../../includes/welcomeBar.php"); ?>
					</ul>
				<!-- Welcome Message Ends Here -->	
                </div>
            </div>
            <div id="main">

                <div id="sidebar">
                    <?php
					// include the corresponding navigation page
                    include("shopSidebar.php");
                    include("../../includes/navigation.php");
					?>     
                </div>

               <!-- main body -->
               <h2>Order History</h2><br><br>
             
                <?php
                $user = $_SESSION['ls_userid'];
                $sql = "SELECT * FROM orders WHERE customerID = '$user' ORDER BY orderTime DESC";
                $orders = mysql_query($sql) or die(mysql_error()); 
                $total = 0.00;
            
                $i = 0;
                while($order = mysql_fetch_assoc($orders)) {                   
                     $total = 0;
                     ?>
                    <table width="65%">
                    <tr style="background-color: #CDC0B0;">
                        <th padding="10">Order #: <?php echo $order[orderID]; ?></th><th padding="10">Status: <?php echo $order[status]; ?>  </th></tr>                    
                    <table width="65%"><tr><th>Product Name</th><th>Size</th><th>Price Paid</th><th>Quantity Ordered</th><th> Subtotal </th></tr>
                    <?php
                    //fetch the order info
                    $itemInfo = mysql_query("SELECT * FROM itemsOrdered WHERE orderID = '$order[orderID]'") or die(mysql_error()); 
                    while($item = mysql_fetch_assoc($itemInfo)) { 
                    // this is just to make the table pretty with alternating tr colours
                        if($i % 2) { 
                            $class = 'row1'; 
                        } 
                        else { 
                            $class = 'row2'; 
                        } 
                        $i++;
                    
                        //select product
                        $product = mysql_query("SELECT * FROM products WHERE productID = '$item[productID]'") or die(mysql_error()); 
                        $product = mysql_fetch_assoc($product);
                        $total += $product[price] * $item[quantity];
                    ?>             
                        <tr class="<?php echo $class; ?>"> 
                            <td align="center"><?php echo $product[name]; ?></td> 
                            <td align="center"><?php echo $product[size]; ?></td> 
                            <td align="center">$<?php echo $product[price]; ?></td> 
                            <td align="center"><?php echo $item[quantity]; ?></td>
                            <td align="center">$<?php echo sprintf("%01.2f", $item[quantity] * $product[price]); ?></td>
                        </tr> 

                    <?php } ?>
                        <tr><th>Total Cost:</th><td colspan="3"></td><td align="center"><b>$<?php echo sprintf("%01.2f", $total); ?></b><td></tr>
                     </table>
                 </table><br><br>
            <?php
            }
            ?>
             
                <div class="clear"></div>

            </div>
			<!-- Footer Goes Here -->
            <?php include("../../includes/footer.php"); ?>
			<!-- Footer Ends Here -->
        </div>
    </div>
</div>
</body>
</html>
